﻿using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using SnmpForm.DbWrapper.DbDataTypes;



namespace SnmpForm.ApSearch
{
    class SearchTask:RequestTask
    {
        private FrmApSearch _objApSearch = null;

        public SearchTask(FrmApSearch objApSearch, List<SearchTarget> list):
            base(list)
        {
            _objApSearch = objApSearch;
        }

        public override void RecvEvent(EndPoint remote, ISnmpMessage response)
        {
            foreach (Variable v in response.Pdu().Variables)
            {
                Console.WriteLine(remote.ToString());
                Console.WriteLine(v);
                if (v.Data.TypeCode != SnmpType.Null)
                {
                    DbWrapper.DbDataTypes.Ap apinfo = new Ap();
                    apinfo.manage_ip = ((IPEndPoint)remote).Address.ToString();
                    apinfo.mark = v.Data.ToString();
                    _objApSearch.Invoke(_objApSearch.newApFinded, new Object[] { apinfo });
                }
            }
        }
        public override void ProgessChangeEvent()
        {
            _objApSearch.Invoke(_objApSearch.updateProgress, new Object[] { GetProgress() });
        }
        public override void TaskPost()
        {
            base.TaskPost();
            _objApSearch.BeginInvoke(_objApSearch.displayLog, new Object[] { "搜索结束" });
            _objApSearch.BeginInvoke(_objApSearch.taskIsStoped, null);
        }
    }
}
